package br.ufrn.cerescaico.sepe.util;

import java.util.Date;
import java.util.StringTokenizer;

/**
 * Universidade Estadual da Paraíba
 * Cidade: Monteiro - Paraíba
 *
 * @author  Ana Emília Victor Barbosa, anaemiliabarbosa@gmail.com <br>
 * @version 1.0 <br>
 *
 * Copyright (C) 2009
 */
public class StringUtil {

        /**
         * 
         * @param str
         * @param subOld
         * @param subNew
         * @return
         */
	public static String replace(String str, String subOld, String subNew) {
		int i = str.indexOf(subOld);

		if (i == -1) {
			return str;
		} else {
			StringBuffer stb = new StringBuffer(str);
			stb.replace(i, i + subOld.length(), subNew);
			return replace(stb.toString(), subOld, subNew);
		}
	}

	/**
	 * Return the string of the date in the format mm/dd/yyyy
	 * @param date The date 
	 * @return The string of the date in the format mm/dd/yyyy
	 */
	public static String stringDate(Date date){
		String srt = date.toString();
		StringTokenizer tokenizer = new StringTokenizer(srt, " ");
		String srtDate = tokenizer.nextToken();
		StringTokenizer token = new StringTokenizer(srtDate, "-");
		String year = token.nextToken();
		String month = token.nextToken();
		String day = token.nextToken();
		return month + "/" + day + "/" + year;	
	}
}